package org.xxforest.game.notsing.screen.rpg.layers;

import org.xxforest.game.core.XX;
import org.xxforest.game.core.scenes.scene2d.XXLayer;
import org.xxforest.game.core.scenes.scene2d.events.XXEvent;
import org.xxforest.game.core.scenes.scene2d.events.XXEventListener;
import org.xxforest.game.core.scenes.scene2d.events.XXEventType;
import org.xxforest.game.core.scenes.scene2d.events.XXKeyCode;
import org.xxforest.game.core.scenes.scene2d.events.listeners.XXInputListener;
import org.xxforest.game.core.scenes.scene2d.events.listeners.XXKeyPressListener;
import org.xxforest.game.core.scenes.scene2d.events.type.XXInputEvent;
import org.xxforest.game.core.scenes.scene2d.events.type.XXKeyPressEvent;
import org.xxforest.game.core.scenes.scene2d.selector.XXScheduleSelector;
import org.xxforest.game.notsing.common.SpiritManager;
import org.xxforest.game.notsing.roles.Spirit;

public class RpgLayer extends XXLayer {
	
	/**	地图精灵*/
	private Spirit spirit ;

	public RpgLayer(float width, float height) {
		super(width, height);
	}

	public static RpgLayer create(float width , float height){
		return new RpgLayer(width, height);
	}
	
	@Override
	public void onCreate() {
		spirit = Spirit.create("images/role/CH00100.png","images/role/CH00101.png","images/role/CH00102.png");
		spirit.setPosition(0, 0);
		this.add(spirit);
		SpiritManager.getInstance().setMainRole(spirit);
		
		
		//按下任意键攻击
		this.setKeyDownEvent(new XXInputListener() {
			
			@Override
			public boolean handle(XXInputEvent event) {
				spirit.attack();
				return false;
			}
		});
		
		//精灵帧屏更新
		XX.director.addSelector(new XXScheduleSelector() {
			
			@Override
			public void run() {
				spirit.nextFrame() ;
			}
		}, 0.1f);
		
		this.touchAble() ;
		this.focusMe() ;
	}

}
